package 力扣日常刷题.木22二月.第09天215;

/**
 * @author 帅小伙
 * @date 2022/2/15
 * @description
 */
public class Demo68合并两个有序数组 {


    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] ans = new int[m + n];
        int i = 0, j = 0;
        while (i < m && j < n) {
            if (nums1[i] <= nums2[j]) ans[i + j] = nums1[i++];
            else ans[i + j] = nums2[j++];
        }
        while (i < m) ans[i + j] = nums1[i++];
        while (j < n) ans[i + j] = nums2[j++];
        for (int k = 0; k < n + m; k++) {
            nums1[k] = ans[k];
        }
    }
}
